#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;


class Number
{
public:
    Number(size_t data = 0)
    : _data(data)
    {

    }

    void print() const
    {
        cout << _data << "  ";
    }

    bool isEven() const 
    {
        return (0 == _data % 2);
    }

    bool isPrime() const
    {
        if(1 == _data)
        {
            return false;
        }

        for(size_t idx = 2; idx <= _data/2; ++idx)
        {
            if( 0 == _data % idx )
            {
                return false;
            }
        }

        return true;
    }

    ~Number()
    {

    }
private:
    size_t _data;
};

int main() {
    vector<Number> vec;
    for (int idx=0; idx<30; idx++){
        vec.push_back(Number(idx));
    }

    // for_each(vec.begin(), vec.end(), mem_fn(&Number::print));

    using namespace placeholders;
    for_each(vec.begin(), vec.end(), bind(&Number::print, _1));// 实际上传入的是 Number对象
    cout << endl;

    // 删除所有的偶数
    vec.erase(remove_if(vec.begin(), vec.end(), mem_fn(&Number::isEven)), vec.end());
    for_each(vec.begin(), vec.end(), mem_fn(&Number::print));
    cout << endl;

    // 删除所有的质数
    vec.erase(remove_if(vec.begin(), vec.end(), mem_fn(&Number::isPrime)), vec.end());
    for_each(vec.begin(), vec.end(), mem_fn(&Number::print));
    cout << endl;


    return 0;
}